package com.ossjk.oa.accounting.mapper;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.ossjk.oa.accounting.entity.CwCapitals;
import com.ossjk.oa.accounting.vo.CwCapitalsVo;
import com.ossjk.oa.accounting.vo.MoneySumVo;
import com.ossjk.oa.accounting.vo.StatisticsVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author chair
 * @since 2020-05-14
 */
public interface CwCapitalsMapper extends BaseMapper<CwCapitals> {
	
	List selectVoPage(Page page, @Param("ew") Wrapper wrapper);
	
    @Select("select   left(max(cptdate),7) from cw_capitals where cptdate<(select min(cptdate) from cw_capitals where left(cptdate,7) = #{mth}) order by cptdate desc")
    String selectPreMth(String mth);
    
    @Select("select   left(min(cptdate),7) from cw_capitals where cptdate>(select max(cptdate) from cw_capitals where left(cptdate,7) = #{mth}) order by cptdate")
    String selectNextMth(String mth);
    
    //选定月份12个月以内的月份
    @Select("select a.cptMth  from (select DISTINCT left(cptdate,7) as cptMth  from   cw_capitals ) a where  a.cptMth >#{mth} order by a.cptMth desc limit 0,12")
    String[] selectMax12Mth(String mth);
 
	@Select("SELECT count(id) FROM cw_capitals where left(cptdate,7)=#{mth} ")
	Long countByMth(@Param("mth")String mth);
 
	List<CwCapitalsVo> selectAllByMth(@Param("mth")String mth);
	
	List<CwCapitalsVo> selectAllByTypeC(@Param("typec")String typec);
 
    @Select(" select *  from v_capitals a   where dt>=#{minMth} and dt<=#{maxMth}  order by a.dt desc")
	List<StatisticsVo> statistics1(@Param("minMth")String minMth,@Param("maxMth")String maxMth);
    @Select("  select *  from v_capitals a     where dt=#{mth} and val>0  order by a.dt desc")
	List<StatisticsVo> statistics2(@Param("mth")String mth);
    @Select("  select *  from v_capitals a       where dt=#{mth} and val<0  order by a.dt desc")
	List<StatisticsVo> statistics3(@Param("mth")String mth);


    List<MoneySumVo> selectSumGBBank(@Param("cptdate")String mth);
}
